//
//  ViewController.m
//  QiongYou
//
//  Created by 操道涛 on 15/12/18.
//  Copyright © 2015年 操道涛. All rights reserved.
//

#import "ViewController.h"
#import "MJRefresh.h"
#import "CustomCell.h"
#import "SendHttpRequest.h"
#import "UIImageView+WebCache.h"
#import "MBProgressHUD+MJ.h"
#import "WebViewController.h"
@interface ViewController ()
{
    UISearchBar *mySearchBar;
//    UIScrollView *bgScrollView;
    UIScrollView *SmallScrollView;
    UIPageControl *_pagecontrol;
    NSTimer *_timer;
    int speed;
    UIButton *Fourbtn;
    UITableView *mytableview;
    NSMutableArray *tableviewSelctionTitle;
    NSInteger number;
    UIView *tableheaderview;
    NSMutableArray *photoMutableArray;
    NSMutableArray *urlMutableArray;
    NSMutableArray *Section1photoArray;
    NSMutableArray *Section2photoArray;
    NSMutableArray *SectionTitleArray;
    UIImageView *Slideimageview;
    NSInteger tag1;
    NSInteger tag2;
    NSInteger tag3;
    NSInteger tag4;
    NSInteger tag5;
    NSInteger tag6;
    
    CustomCell *cell;
    
   
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self creatsearchBar];
    [self creatTableview];
    [self getcellimage];
    
}
- (void)getSlideImage{
    NSString *urlstr=@"http://open.qyer.com/qyer/recommands/entry?app_installtime=1435837675&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=6.3&track_device_info=iPhone7%2C2&track_deviceid=94600906-5BB7-43E7-9E16-C479A03EE469&track_os=ios%25208.3&v=1";

    [MBProgressHUD showMessage:@"加载中" toView:self.view];
    [SendHttpRequest get:urlstr success:^(id responseObj) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"%@",dic);
        NSDictionary *data=dic[@"data"];
        NSMutableArray *slideArray=data[@"slide"];
        photoMutableArray=[[NSMutableArray alloc]init];
        urlMutableArray=[[NSMutableArray alloc]init];
//        NSLog(@"slideArray  %d",slideArray.count);
        for (NSDictionary *dict in slideArray) {
            NSString *photo=dict[@"photo"];
            NSString *urlstr=dict[@"url"];
            [photoMutableArray addObject:photo];
            [urlMutableArray addObject:urlstr];
        }
        SmallScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 150*Scaley)];
        [SmallScrollView setContentOffset:CGPointMake(photoMutableArray.count*ScreenWidth, 0) animated:YES];
        [SmallScrollView setPagingEnabled:YES];
        SmallScrollView.showsHorizontalScrollIndicator=NO;
        SmallScrollView.showsVerticalScrollIndicator=NO;
        SmallScrollView.contentSize=CGSizeMake(photoMutableArray.count*ScreenWidth, 150*Scaley);
        [SmallScrollView setDelegate:self];
        SmallScrollView.bounces=NO;
        [tableheaderview addSubview:SmallScrollView];
        
        for (int i=0; i<photoMutableArray.count; i++) {
               Slideimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, 150*Scaley)];
                [Slideimageview sd_setImageWithURL:[photoMutableArray objectAtIndex:i]];
                 Slideimageview.tag=i+1;
                 [Slideimageview setUserInteractionEnabled:YES];
            UITapGestureRecognizer *Gesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onclickchoosePhoto:)];
            Gesture.numberOfTouchesRequired = 1;
            Gesture.view.tag=Slideimageview.tag;
            [Slideimageview addGestureRecognizer:Gesture];
                 [SmallScrollView addSubview:Slideimageview];
            }
        
        _pagecontrol=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, 60*Scalex, 20*Scaley)];
        [_pagecontrol setCenter:CGPointMake(ScreenWidth/2, 120*Scaley)];
        _pagecontrol.currentPage=0;
        _pagecontrol.numberOfPages=photoMutableArray.count;
        _pagecontrol.pageIndicatorTintColor=[UIColor grayColor];
        _pagecontrol.currentPageIndicatorTintColor=[UIColor whiteColor];
        [mytableview.tableHeaderView addSubview:_pagecontrol];

    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"请求失败"];
    }];
    
}
#pragma Slideimageview点击事件
- (void)onclickchoosePhoto:(id)sender{
    UITapGestureRecognizer *tap=(UITapGestureRecognizer *)sender;
    UIImageView *imgview=(UIImageView *)tap.view;
    WebViewController *Webview=[[WebViewController alloc]init];
    Webview.imgTag=imgview.tag;
    NSLog(@"%ld",Webview.imgTag);
    [self.navigationController pushViewController:Webview animated:YES];
}

- (void)getcellimage{
    NSString *urlstr=@"http://open.qyer.com/qyer/recommands/entry?app_installtime=1435837675&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=6.3&track_device_info=iPhone7%2C2&track_deviceid=94600906-5BB7-43E7-9E16-C479A03EE469&track_os=ios%25208.3&v=1";
    
    [MBProgressHUD showMessage:@"加载中" toView:self.view];
    [SendHttpRequest get:urlstr success:^(id responseObj) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"dic????  %@",dic);
        NSDictionary *data=dic[@"data"];
        NSMutableArray *subjectArray=data[@"discount"];
        NSMutableArray *mguideArray=data[@"mguide"];
        Section1photoArray=[[NSMutableArray alloc]init];
        for (NSDictionary *dict in subjectArray) {
            NSString *photo=dict[@"photo"];
            NSString *title=dict[@"title"];
            [Section1photoArray addObject:photo];
            [SectionTitleArray addObject:title];
        }
        Section2photoArray=[[NSMutableArray alloc]init];
        for (NSDictionary *dict1 in mguideArray) {
            NSString *photo=dict1[@"photo"];
            [Section2photoArray addObject:photo];
//            NSLog(@"Section2photoArray  %@",Section2photoArray);
        }
        [mytableview reloadData];
     } failure:^(NSError *error) {
        [MBProgressHUD showError:@"请求失败"];
    }];

}
- (void)creatTableview{
    tableviewSelctionTitle=[[NSMutableArray alloc]initWithObjects:@"发现下一站",@"抢特价折扣",@"看热门游记", nil];
    mytableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 60*Scaley, ScreenWidth, ScreenHeight-60*Scaley-TabBarHeight)style:UITableViewStyleGrouped];
    mytableview.delegate=self;
    mytableview.dataSource=self;
    mytableview.separatorStyle=NO;
    mytableview.rowHeight=100*Scaley;
    mytableview.bounces=YES;
    mytableview.contentSize=CGSizeMake(ScreenWidth, ScreenHeight*3);
    mytableview.showsHorizontalScrollIndicator=NO;
    mytableview.showsVerticalScrollIndicator=NO;
    [self.view addSubview:mytableview];
    [mytableview addHeaderWithTarget:self action:@selector(upRefresh)];
    [mytableview addFooterWithTarget:self action:@selector(downRefresh)];
    mytableview.headerRefreshingText=@"正在刷新";
    mytableview.footerRefreshingText=@"正在加载";
    [self creatScrollview];
    [self creatFourButton];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20*Scaley;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 40*Scaley;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            number=2;
            break;
        case 1:
            number=3;
            break;
        case 2:
            number=10;
            break;
        default:
            break;
    }
    return number;
}
#pragma cell里面的image点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        if ([indexPath indexAtPosition:1]==0) {
            tag1=100;
            WebViewController *webview=[[WebViewController alloc]init];
            webview.Section0cellimg1Tag=tag1;
            [self.navigationController pushViewController:webview animated:YES];
        }else if ([indexPath indexAtPosition:1]==1){
            tag2=200;
            WebViewController *webview=[[WebViewController alloc]init];
            webview.Section0cellimg2Tag=tag2;
            [self.navigationController pushViewController:webview animated:YES];
        }
    }else if (indexPath.section==1){
        
        if ([indexPath indexAtPosition:1]==0) {
            tag3=100;
            WebViewController *webview=[[WebViewController alloc]init];
            webview.Section1cellimg1Tag=tag3;
            [self.navigationController pushViewController:webview animated:YES];
        }else if ([indexPath indexAtPosition:1]==1){
            tag4=200;
            WebViewController *webview=[[WebViewController alloc]init];
            webview.Section1cellimg2Tag=tag4;;
            [self.navigationController pushViewController:webview animated:YES];
        }else if ([indexPath indexAtPosition:1]==2){
            tag5=300;
            WebViewController *webview=[[WebViewController alloc]init];
    
            webview.Section1cellimg3Tag=tag5;
            [self.navigationController pushViewController:webview animated:YES];
        }

    }else if (indexPath.section==2){
        tag6=400;
        WebViewController *webview=[[WebViewController alloc]init];
        webview.Section2cellimgTag=tag6;
        [self.navigationController pushViewController:webview animated:YES];
    }
   
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"cell";
    cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    if (indexPath.section==0) {
        
        if ([indexPath indexAtPosition:1]==0) {
            cell.imgview1=[[UIImageView alloc]initWithFrame:CGRectMake(5*Scalex/2, 0, (ScreenWidth-5*Scalex), 100*Scaley-5/2*Scaley)];
            [cell.imgview1 sd_setImageWithURL:[Section1photoArray objectAtIndex:0]];
            [cell.imgview1 setUserInteractionEnabled:YES];
            [cell.contentView addSubview:cell.imgview1];
        }else if (indexPath.row==1){
            for (int i=0; i<2; i++) {
                cell.imgview2=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2*i+5*Scalex/2, 5/2*Scaley, (ScreenWidth-10*Scalex)/2, 100*Scaley-5/2*Scaley)];
                [cell.imgview2 sd_setImageWithURL:[Section1photoArray objectAtIndex:i+1]];
                [cell.contentView addSubview:cell.imgview2];
                
                 [cell.imgview2 setUserInteractionEnabled:YES];
                
            }
        }

    }else if (indexPath.section==1){
        if (indexPath.row==0) {
            cell.imgview1=[[UIImageView alloc]initWithFrame:CGRectMake(5*Scalex/2, 0, (ScreenWidth-5*Scalex), 100*Scaley-5/2*Scaley)];
            [cell.imgview1 sd_setImageWithURL:[Section1photoArray objectAtIndex:0]];
            [cell.contentView addSubview:cell.imgview1];
            [cell.imgview1 setUserInteractionEnabled:YES];
        }else if(indexPath.row==1){
            for (int i=0; i<2; i++) {
                cell.imgview2=[[UIImageView alloc]initWithFrame:CGRectMake((ScreenWidth)/2*i+5*Scalex/2, 5/2*Scaley, (ScreenWidth-10*Scalex)/2, 100*Scaley-5/2*Scaley)];
                [cell.imgview2 sd_setImageWithURL:[Section1photoArray objectAtIndex:i+1]];
                [cell.contentView addSubview:cell.imgview2];
                [cell.imgview2 setUserInteractionEnabled:YES];
              }

        }else if (indexPath.row==2){
            
            for (int i=0; i<2; i++) {
                
                cell.imgview3=[[UIImageView alloc]initWithFrame:CGRectMake((ScreenWidth)/2*i+5*Scalex/2, 5/1*Scaley, (ScreenWidth-10*Scalex)/2, 100*Scaley-5/2*Scaley)];
                [cell.imgview3 sd_setImageWithURL:[Section1photoArray objectAtIndex:i+1]];
                [cell.contentView addSubview:cell.imgview3];
                [cell.imgview3 setUserInteractionEnabled:YES];
            }

        }
        
    }else if (indexPath.section==2){
    
        cell.imgview1=[[UIImageView alloc]initWithFrame:CGRectMake(5*Scalex/2, 0, (ScreenWidth-5*Scalex), 100*Scaley-5*Scaley/2)];
        [cell.imgview1 sd_setImageWithURL:[Section1photoArray objectAtIndex:0]];
        [cell.contentView addSubview:cell.imgview1];
        [cell.imgview1 setUserInteractionEnabled:YES];
    }
    return cell;
}
#pragma section底部
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSMutableArray *sectionFootTitle=[[NSMutableArray alloc]initWithObjects:@"查看更多精彩专题",@"查看全部特价折扣",@"更多精彩", nil];
    UIView *view = [[UIView alloc] init];
    
    UIButton *footerbutton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150*Scalex, 30*Scaley)];
    [footerbutton setCenter:CGPointMake(ScreenWidth/2, 40/2*Scaley)];
    if (section==0) {
        [footerbutton setTitle:[sectionFootTitle objectAtIndex:section] forState:UIControlStateNormal];
    }else if (section==1){
         [footerbutton setTitle:[sectionFootTitle objectAtIndex:section] forState:UIControlStateNormal];
    }else if (section==2){
         [footerbutton setTitle:[sectionFootTitle objectAtIndex:section] forState:UIControlStateNormal];
    }
    [footerbutton addTarget:self action:@selector(footerbuttonclick:) forControlEvents:UIControlEventTouchUpInside];
    [footerbutton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    footerbutton.titleLabel.font=[UIFont systemFontOfSize:14];
    [view addSubview:footerbutton];

   
    return view;
    
}
- (void)footerbuttonclick:(UIButton *)sender{
    
     [sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [tableviewSelctionTitle objectAtIndex:section];
}

- (void)creatFourButton{
    UIView *fourbtnview=[[UIView alloc]initWithFrame:CGRectMake(0, 150*Scaley, ScreenWidth, 100*Scaley)];
    [fourbtnview setBackgroundColor:[UIColor whiteColor]];
    [tableheaderview addSubview:fourbtnview];
    NSMutableArray *FourbtnTitleArray=[[NSMutableArray alloc]initWithObjects:@"看锦囊",@"抢折扣",@"订酒店",@"旅途中", nil];
    for (int i=0; i<4; i++) {
        Fourbtn=[[UIButton alloc]initWithFrame:CGRectMake((ScreenWidth-4*50*Scalex)/5*(i+1)+i*50*Scalex, 20*Scaley, 50*Scalex, 80*Scaley)];
        UIImageView *Fourbtnimg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50*Scalex, 50*Scaley)];
        [Fourbtnimg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+5]]];
        [Fourbtn addSubview:Fourbtnimg];
        UILabel *FourbtnTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 60, 50*Scalex, 20*Scaley)];
        [FourbtnTitle setTextColor:[UIColor blackColor]];
        [FourbtnTitle setText:FourbtnTitleArray[i]];
        [FourbtnTitle setFont:[UIFont systemFontOfSize:14 weight:0]];
        [FourbtnTitle setTextAlignment:NSTextAlignmentCenter];
        [Fourbtn addSubview:FourbtnTitle];
        [Fourbtn addTarget:self action:@selector(Fourbtnclick:) forControlEvents:UIControlEventTouchUpInside];
        [fourbtnview addSubview:Fourbtn];
    }
}
- (void)Fourbtnclick:(UIButton *)sender{
    Fourbtn=sender;
    UIAlertController *Alc=[UIAlertController alertControllerWithTitle:@"提醒" message:@"你确定还要点进去???" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction=[UIAlertAction actionWithTitle:@"傻了吧" style:UIAlertActionStyleDefault handler:nil];
    [Alc addAction:okAction];
    UIAlertAction *CancelAction=[UIAlertAction actionWithTitle:@"回去吧" style:UIAlertActionStyleCancel handler:nil];
    [Alc addAction:CancelAction];
    [self presentViewController:Alc animated:YES completion:nil];
}
- (void)creatScrollview{
    
    [self getSlideImage];
    tableheaderview=[[UIView alloc]initWithFrame:CGRectMake(0, 60*Scalex, ScreenWidth, 270*Scaley)];
    mytableview.tableHeaderView=tableheaderview;
    
    
//    SmallScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 150*Scaley)];
//    [SmallScrollView setContentOffset:CGPointMake(photoMutableArray.count*ScreenWidth, 0) animated:YES];
//    [SmallScrollView setPagingEnabled:YES];
//    SmallScrollView.showsHorizontalScrollIndicator=NO;
//    SmallScrollView.showsVerticalScrollIndicator=NO;
//    SmallScrollView.contentSize=CGSizeMake(photoMutableArray.count*ScreenWidth, 150*Scaley);
//    [SmallScrollView setDelegate:self];
//    SmallScrollView.bounces=NO;
//    [tableheaderview addSubview:SmallScrollView];
//    for (int i=0; i<photoMutableArray.count; i++) {
//        UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, 150*Scaley)];
////        [imageview setImage:[UIImage imageNamed:[NSString stringWithFormat:@"banner%d",i+1]]];
//        [imageview sd_setImageWithURL:[photoMutableArray objectAtIndex:i]];
//        [SmallScrollView addSubview:imageview];
//    }
//    _pagecontrol=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, 60*Scalex, 20*Scaley)];
//    [_pagecontrol setCenter:CGPointMake(ScreenWidth/2, 120*Scaley)];
//    _pagecontrol.currentPage=0;
//    _pagecontrol.numberOfPages=photoMutableArray.count;
//    _pagecontrol.pageIndicatorTintColor=[UIColor grayColor];
//    _pagecontrol.currentPageIndicatorTintColor=[UIColor whiteColor];
//    [mytableview.tableHeaderView addSubview:_pagecontrol];
    
    _timer=[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(ontime) userInfo:nil repeats:YES];
    [_timer fire];
    speed=-1;

}//同步。。。和图片
- (void)ontime{
    if (_pagecontrol.currentPage==0||_pagecontrol.currentPage==photoMutableArray.count-1) {
        speed=-speed;
    }
    _pagecontrol.currentPage=_pagecontrol.currentPage+speed;
    
    [SmallScrollView setContentOffset:CGPointMake(_pagecontrol.currentPage*ScreenWidth, 0) animated:YES];
}
//已经结束减速的时候（停止拖动）
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _pagecontrol.currentPage=SmallScrollView.contentOffset.x/ScreenWidth;
}
/**
 *  下拉刷新
 */
- (void)upRefresh{
    NSLog(@"刷新成功");
    [mytableview headerEndRefreshing];
}
/**
 *  上拉加载
 */
- (void)downRefresh{
    NSLog(@"加载成功");
    [mytableview footerEndRefreshing];
}
- (void)creatsearchBar{
    UIView *headview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60*Scaley)];
    [headview setBackgroundColor:[UIColor greenColor]];
    [self.view addSubview:headview];
    
    mySearchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(45*Scalex, 25*Scalex, 250*Scalex, 30*Scaley)];
    mySearchBar.delegate=self;
    mySearchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:mySearchBar.bounds.size];
    mySearchBar.barStyle=UISearchBarStyleDefault;
    mySearchBar.keyboardType=UIKeyboardAppearanceDefault;
    mySearchBar.placeholder=@"搜索目的地、帖子、特价、穷游er";
    mySearchBar.contentMode=UIViewContentModeCenter;
    UITextField *searchfiled=[mySearchBar valueForKey:@"_searchField"];
    [searchfiled setValue:[UIFont systemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
//    [searchfiled setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [headview addSubview:mySearchBar];
    
    UIButton *SouSuobtn=[[UIButton alloc]initWithFrame:CGRectMake(10*Scalex, 25*Scaley, 25*Scalex, 25*Scaley)];
    [SouSuobtn setBackgroundImage:[UIImage imageNamed:@"searchbar_textfield_search_icon@2x"] forState:UIControlStateNormal];
    [headview addSubview:SouSuobtn];
}
#pragma 点击空白处让键盘隐藏
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [mySearchBar resignFirstResponder];
}
//取消searchbar背景色
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
#pragma UISearchBardelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    NSLog(@"shouldBeginEditing");
    return YES;
}
//开始编辑 UISearchBar的textview时，调用此函数
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    NSLog(@"BeginEndEditing");
}
//要求
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
    return YES;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
    NSLog(@"DidEndEditing");
}
//当textview的文字改变或者清除的时候调用此方法，搜索栏目前的状态正在编辑，在搜索文本字段中的当前文本
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
    NSLog(@"textDidChange");
}

@end
